<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Git代码托管服务 | 学习笔记</title><meta name="author" content="lzoxun"><meta name="copyright" content="lzoxun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="常用远程托管平台GigHub | 码云 | GitLab 配置用户配置123456789101112131415161718192021222324git config --global user.name &quot;xxx&quot;git config --global user.email &quot;xxx@qq.com&quot;git config --[local&#x2F;global&#x2F;s">
<meta property="og:type" content="article">
<meta property="og:title" content="Git代码托管服务">
<meta property="og:url" content="http://example.com/2023/07/22/other/other-git/index.html">
<meta property="og:site_name" content="学习笔记">
<meta property="og:description" content="常用远程托管平台GigHub | 码云 | GitLab 配置用户配置123456789101112131415161718192021222324git config --global user.name &quot;xxx&quot;git config --global user.email &quot;xxx@qq.com&quot;git config --[local&#x2F;global&#x2F;s">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-07-22T07:14:09.683Z">
<meta property="article:modified_time" content="2023-07-22T07:14:09.683Z">
<meta property="article:author" content="lzoxun">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/07/22/other/other-git/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":true,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Git代码托管服务',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-07-22 15:14:09'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="学习笔记"><span class="site-name">学习笔记</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Git代码托管服务</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-22T07:14:09.683Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-07-22T07:14:09.683Z" title="更新于 2023-07-22 15:14:09">2023-07-22</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Git代码托管服务"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>常用远程托管平台<a target="_blank" rel="noopener" href="https://github.com/">GigHub</a> | <a target="_blank" rel="noopener" href="https://gitee.com/">码云</a> | <a target="_blank" rel="noopener" href="https://about.gitlab.com/">GitLab</a></p>
<h2 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h2><h3 id="用户配置"><a href="#用户配置" class="headerlink" title="用户配置"></a>用户配置</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;xxx&quot;</span><br><span class="line">git config --global user.email &quot;xxx@qq.com&quot;</span><br><span class="line"></span><br><span class="line">git config --[local/global/system] obj.键 + 空格 + 值 //修改、添加配置</span><br><span class="line">git config --[local/global/system] --unset obj.键  //删除配置</span><br><span class="line"></span><br><span class="line">查看</span><br><span class="line">git config --list</span><br><span class="line">git config user.name</span><br><span class="line"></span><br><span class="line">git 配置分为三部分</span><br><span class="line">    1、本地配置位于本地仓库的隐藏文件夹.git/config 文件  默认以core开头</span><br><span class="line">       git config --local --list (只 本地配置)</span><br><span class="line"></span><br><span class="line">    2、全局配置位于用户的根目录下 .gitconfig  //需要进行过全局配置才会有该文件</span><br><span class="line">       git config --global --list (只 全局配置)</span><br><span class="line"></span><br><span class="line">    3、系统配置位于git的安装目录下</span><br><span class="line">       git config --system --list (只 系统配置)</span><br><span class="line"></span><br><span class="line">    (优先级依次降低 如果三个配置文件中都有同样的配置优先以本地为准)</span><br><span class="line"></span><br><span class="line">命令行汉化</span><br><span class="line">echo &quot;alias git=&#x27;LANG=zh_CN.utf8 git&#x27;&quot; &gt;&gt; ~/.zshrc</span><br></pre></td></tr></table></figure>

<blockquote>
<p>操作完成之后信息保存在<strong>C 盘的用户</strong>下**.gitconfig**文件中，作用只是标识你是谁,与远程仓库账户无关</p>
</blockquote>
<h3 id="获取仓库"><a href="#获取仓库" class="headerlink" title="获取仓库"></a>获取仓库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git init #生成隐藏文件夹.git</span><br><span class="line">或</span><br><span class="line">git clone 项目地址</span><br></pre></td></tr></table></figure>

<h3 id="工作区间"><a href="#工作区间" class="headerlink" title="工作区间"></a>工作区间</h3><blockquote>
<p>工作区：包含.git 版本库的目录<br>暂存区：.git 版本库下的 index 文件就是暂存区(stage),是一个临时保存修改文件的地方<br>版本库：项目文件夹下.git 隐藏文件夹就是版本库,储存这项目配置信息、日志信息、文件版本等<br>远程仓库：</p>
</blockquote>
<p>工作区 git add . 到暂存区 commit 版本库 push 远程仓库</p>
<h3 id="文件状态"><a href="#文件状态" class="headerlink" title="文件状态"></a>文件状态</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">untracked : # 未跟踪(未被纳入版本控制)</span><br><span class="line">tracked   : # 以跟踪(纳入版本控制)</span><br><span class="line">    Unmodified # 未修改</span><br><span class="line">    Modified   # 已修改</span><br><span class="line">    Staged     # 已暂存</span><br><span class="line"></span><br><span class="line">git status # 指令查看文件状态</span><br></pre></td></tr></table></figure>

<h3 id="从本地到远程仓库流程"><a href="#从本地到远程仓库流程" class="headerlink" title="从本地到远程仓库流程"></a>从本地到远程仓库流程</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">mkdir project</span><br><span class="line">cd project</span><br><span class="line">git init</span><br><span class="line">touch README.md</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m &quot;first commit&quot;</span><br><span class="line">git remote add origin https://gitee.com/liaozhongxun/project.git</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<h2 id="指令"><a href="#指令" class="headerlink" title="指令"></a>指令</h2><h3 id="常用指令"><a href="#常用指令" class="headerlink" title="常用指令"></a>常用指令</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">git status [-s]# 查看文件状态</span><br><span class="line">git add file|.|* # 将指定文件、所有新增编辑文件、所有编辑文件 添加到暂存区</span><br><span class="line">git reset &lt;file-name&gt;           # 从暂存区 commit 的修改恢复指定到工作区</span><br><span class="line">git reset -- .                  # 从暂存区恢复所有文件到工作区</span><br><span class="line">git reset --hard                # 把暂存区的修改退回到工作区</span><br><span class="line">git reset --hard HEAD~1         # 回头n个版本</span><br><span class="line">git commit -m &#x27;日志信息&#x27; # 将暂存区文件提交到版本库(状态变为已跟踪未修改 看不到了)</span><br><span class="line">git commit -a -m &#x27;日志信息&#x27; # 不用add 直接添加到版本库</span><br><span class="line">git commit 回车(进入编辑器) --&gt; i(进入编辑模式) --&gt; esc (退出编辑模式) --&gt; :wq(保存并退出)</span><br><span class="line"></span><br><span class="line">git stash  # 工作区的修改和暂存区的修改</span><br><span class="line">git stash pop # 恢复</span><br><span class="line"></span><br><span class="line">git log # 查看日志记录</span><br><span class="line">	commit id  重要</span><br><span class="line">git log --oneline  //以简洁的一行显示，包含简洁哈希索引值</span><br><span class="line">git log --pretty=oneline //查看日志且并且显示版本</span><br><span class="line">git log --stat     //显示每个commit中哪些文件被修改,分别添加或删除了多少行</span><br></pre></td></tr></table></figure>

<h3 id="撤销"><a href="#撤销" class="headerlink" title="撤销"></a>撤销</h3><blockquote>
<p>git revert 是用一次新的 commit 来回滚之前的 commit，git reset 是直接删除指定的 commit。看似达到的效果是一样的，其实完全不同：<br>1、上面我们说的如果你已经 push 到线上代码库，reset 删除指定 commit 以后，你 git push 可能导致一大堆冲突，但是 revert 不会。<br>2、如果在日后现有分支和历史分支需要合并的时候，reset 恢复部分的代码依然会出现在历史分支里，但是 revert 方向提交的 commit 并不会出现在历史分支里。<br>3、reset 是在正常的 commit 历史中，删除了指定的 commit，这时 HEAD 是向后移动了。而 revert 是在正常的 commit 历史中再 commit 一次，只不过是反向提交，它的 HEAD 是一直向前的。</p>
</blockquote>
<ul>
<li>撤销指定 commit<ul>
<li>reset(工作区回退)<ul>
<li><code>git reset --hard commit_id</code><ul>
<li><code>--soft</code>:保留源码，只回退 commit 信息到某个版本，不涉及 index 的回退。如果还需要提交，直接 commit 即可。</li>
<li><code>--mixed</code>：会保留源码，只是将 git commit 和 index 的信息回退到了某个版本。（git reset 默认的就是–mixed 模式，即 git reset 等价于 git reset –mixed）</li>
<li><code>--hard</code>：源码也会回退到某个版本，commit 和 index 都会回退到某个版本。(注意这种方式是会改变本地代码仓库源码)</li>
</ul>
</li>
<li>当然有人在 push 代码以后，也使用 reset –hard 回退代码到某个版本之前。但是这样会有一个问题，你线上的代码没有变，线上 commit、index 都没有变，当你把本地代码修改完提交的时候你会发现全是冲突……..所以，这种情况你要使用下面的方式</li>
</ul>
</li>
<li>revert<ul>
<li>同时回滚远程线上代码</li>
<li><code>git revert commit_id</code></li>
</ul>
</li>
</ul>
</li>
<li>撤销工作区修改<ul>
<li>未跟踪<ul>
<li><code>git clean -fd</code> 丢弃所有位跟踪</li>
</ul>
</li>
<li>未 add<ul>
<li><code>git checkout files</code></li>
<li><code>git checkout -- .</code> 撤销所有修改过没有add的改变</li>
</ul>
</li>
<li>已经 git add<ul>
<li><code>git reset HEAD</code> 撤销暂存状态回到 add 前,再<code>git checkout files</code>回到修改前</li>
<li><code>git reset file</code>撤销指定文件</li>
<li><code>git reset</code>撤销所有文件</li>
<li><code>HEAD</code> 代表回到 HEAD 指向的 commit</li>
</ul>
</li>
<li>已 add 并再次修改<ul>
<li>先 1 在 2</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="远程仓库"><a href="#远程仓库" class="headerlink" title="远程仓库"></a>远程仓库</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">git remote [-v]# 查看远程仓库</span><br><span class="line">git remote show origin # 查看远程仓库名为origin的详细信息</span><br><span class="line">git remote add &lt;name&gt; &lt;url&gt; # 添加远程仓库name建议用origin,一个项目可以添加到多个远程仓库</span><br><span class="line">							# &lt;name&gt;为本地自定义远程仓库别名，clone项目默认都是origin</span><br><span class="line">git remote rm &lt;name&gt; # 端口与指定名称的远程仓库的关联</span><br><span class="line">                     # 远程项目改名 github 会帮你重定向到此项目，不更新remote也能正常提交</span><br><span class="line">git push &lt;name&gt; &lt;branch&gt; # 提交到远程,如果后期不需要跟换仓库名与分支可以直接git push</span><br><span class="line"></span><br><span class="line">git clone &lt;url&gt; # 从远程克隆项目</span><br><span class="line">git pull # 从远程拉去最新内容，与fetch的差别pull会自动合并</span><br><span class="line">         # 第一次链接远程且本地有文件，pull时不允许合并添加 --allow-unrelated-histories强行合并</span><br><span class="line">git fetch # 从远程拉去最新内容</span><br><span class="line">    git merge origin/master # 手动指定仓库名/分支合并到工作区</span><br></pre></td></tr></table></figure>

<h3 id="分支"><a href="#分支" class="headerlink" title="分支"></a>分支</h3><blockquote>
<p>分支分为本地放在(本地操作是后面跟的那个如 master)和远程分支(远程 tags 旁边那个如 origin&#x2F;master)</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">git branch # 查看所有本地分支</span><br><span class="line">git branch -r # 查看所有远程分支</span><br><span class="line">git branch -a # 查看本地与远程的分支（远程分支前面会有remotes表示这是远程的）</span><br><span class="line"></span><br><span class="line">git branch &lt;branch name&gt; # 创建本地分支</span><br><span class="line">git checkout &lt;branch name&gt; # 切换分支</span><br><span class="line">    # 切换分支前，需要将修改通过 commit 提交贮藏</span><br><span class="line">    # 切换分支后，没有add的文件，会跟到新分区</span><br><span class="line">git checkout -b &lt;branch name&gt; # 创建并切换</span><br><span class="line">git push origin &lt;branch name&gt; # 将本地分支推送到远程( 推送非当前分支的其他分支，与当前分支的改变无关 )</span><br><span class="line">git checkout -b &lt;new branch name&gt; origin/远程分支名 # 拉取指定远程分支</span><br><span class="line">git checkout --track origin/abranch # 拉取远程分支，使用相同的名字</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">git checkout . # 放弃所有的文件修改</span><br><span class="line">此命令用来放弃掉所有还没有加入到缓存区（就是 git add 命令）的修改：内容修改与整个文件删除。但是此命令不会删除掉刚新建的文件。因为刚新建的文件还没已有加入到 git 的管理系统中。所以对于git是未知的。自己手动删除就好了。</span><br><span class="line"></span><br><span class="line">git checkout -f # 丢弃本地修改,还可以删除没有跟踪的</span><br><span class="line"></span><br><span class="line">git clone -b branchA http://xxx #直接隆指定分支</span><br><span class="line"></span><br><span class="line">git cherry-pick &lt;commitHash&gt; #当前分支如果需要某个分支的指定提交,</span><br><span class="line">                             #你需要另一个分支的所有代码变动就用 merge</span><br><span class="line">git merge &lt;branch name&gt; # 将指定分支版本库内容合并到当前分支</span><br><span class="line">                        # 如果两个分支多同一个文件同一部分进行不同修改，会产生冲突</span><br><span class="line">                        # 解决方法打开文件去除不要的在提交上去就行了</span><br><span class="line"></span><br><span class="line">git branch -d &lt;branch name&gt; # 删除本地分支(要在其他分支上操作，并且新增内容要提交到远程才能成功)</span><br><span class="line">git branch -D &lt;branch name&gt; # 删除本地分支(要在其他分支上操作，并且新增内容可以不用提交,D就是强行删除)</span><br><span class="line">git push origin -d &lt;branch name&gt; # 删除远程分支</span><br><span class="line"></span><br><span class="line">``checko`</span><br><span class="line"></span><br><span class="line">分支的运用案例</span><br><span class="line">![](../../static/img/gitbranch.png)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">## 标签</span></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">&gt; </span><span class="language-bash">记录特定事件点的状态</span></span><br><span class="line"></span><br><span class="line">```shell</span><br><span class="line">git tag &lt;tag name&gt; # 创建标签</span><br><span class="line">git tag -a v1.4 -m &quot;my version 1.4&quot;</span><br><span class="line">git show &lt;tag name&gt; # 查看标签</span><br><span class="line">git push origin &lt;tag name&gt; # 将指定标签推送到远程</span><br><span class="line">git checkout -b &lt;branch name&gt; &lt;tag name&gt; # 检出指定分支 指定标签的代码</span><br><span class="line"></span><br><span class="line">git tag -d &lt;tag name&gt; # 删除标签</span><br><span class="line">git push origin :refs/tags/&lt;tag name&gt; # 删除远程标签</span><br></pre></td></tr></table></figure>

<h3 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git rm file # 删除工作区文件(要通过commit提交到版本库才会删除仓库中的文件)</span><br><span class="line">touch .gitignore # 创建文件</span><br></pre></td></tr></table></figure>

<h2 id="忽略文件-gitignore"><a href="#忽略文件-gitignore" class="headerlink" title="忽略文件 .gitignore"></a>忽略文件 .gitignore</h2><blockquote>
<p>.gitignore只能忽略那些原来没有被追踪的文件,否则无效（要通过 git rm .env.development –cached ）</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">*.txt  # 忽略所有.txt格式文件</span><br><span class="line">!list.txt # 不需要忽略指定文件</span><br><span class="line">/filename # 忽略指定文件名</span><br><span class="line">build/    # 忽略指定文件夹</span><br><span class="line">doc/*.txt # 忽略doc文件夹下的.txt文件</span><br><span class="line">doc/**/*.txt # 忽略doc下所有.txt文件</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="GIT-协议"><a href="#GIT-协议" class="headerlink" title="GIT 协议"></a>GIT 协议</h2><p>git 支持一下四种协议</p>
<ul>
<li>本地协议(Local)</li>
<li>HTTPS 协议</li>
<li>SSH 协议</li>
<li>GiT 协议</li>
</ul>
<blockquote>
<p>GitHub 与码云目前常用 HTTPS 与 SSH 协议,平时大多使用 HTTPS 协议</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/liaozhongxun/xxx.git</span><br></pre></td></tr></table></figure>

<h3 id="SSH"><a href="#SSH" class="headerlink" title="SSH"></a>SSH</h3><blockquote>
<p>SSH (Secure Shell 安全外壳协议) 的缩写 可以不要每次输入用户名密码，而是利用公钥和私钥进行比对</p>
</blockquote>
<p>1、git 下输入 ssh-keygen|ssh-keygen -t rsa 连续回车生成公私钥（公私钥与本台计算机有关）</p>
<ul>
<li>linux 需要安装 <code>openssh</code></li>
</ul>
<p>2、公私钥匙用户家目录下的 .ssh 文件夹中<br>私钥 : id_rsa<br>公钥 : id_rsa.pub</p>
<p>3、复制公钥的内容到远程仓库(GitHub 或 开源中国等）<br>添加成功后本台计算机就能和远程仓库进行 ssh 交互了</p>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1yz4y1y7RQ?p=40">参考资料 后续继续</a></p>
<h3 id="linux-与-linux-ssh-设置"><a href="#linux-与-linux-ssh-设置" class="headerlink" title="linux 与 linux ssh 设置"></a>linux 与 linux ssh 设置</h3><p>1、两个主机都生成公钥私钥<br>2、连接主机 <code>ssh-copy-id -i ./id_rsa.pub root@114.115.212.xxx</code> 向目标主机114 上传公钥<br>3、ssh <a href="mailto:&#x72;&#111;&#x6f;&#x74;&#64;&#x78;&#x78;&#x78;&#46;&#120;&#120;&#120;&#46;&#x78;&#x78;&#x78;&#x2e;&#120;&#x78;">&#x72;&#111;&#x6f;&#x74;&#64;&#x78;&#x78;&#x78;&#46;&#120;&#120;&#120;&#46;&#x78;&#x78;&#x78;&#x2e;&#120;&#x78;</a> 测试是否可用直接连接</p>
<p>win 连 linux 可能需要在git bash上操作</p>
<p>或<br>远程主机直接将客户端的公钥加入 ~&#x2F;.ssh&#x2F;authorized_keys 文件中</p>
<h2 id="git-服务器环境搭建"><a href="#git-服务器环境搭建" class="headerlink" title="git 服务器环境搭建"></a>git 服务器环境搭建</h2><ul>
<li>进入 &#x2F;usr&#x2F;src 下载 gitisos</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum install -y python python-setuptools git-core # 系统一般有自动基本可以不用安装</span><br><span class="line">git clone git://github.com/res0nat0r/gitosis.git</span><br><span class="line">cd gitosis</span><br><span class="line">python setup.py install</span><br></pre></td></tr></table></figure>

<ul>
<li>管理员客户端通过 ssh 生成公钥</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa # 用户目录下 /.ssh/id_rsa.pub</span><br></pre></td></tr></table></figure>

<ul>
<li>初始化项目</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">新建一个git用户</span></span><br><span class="line">useradd -m git</span><br><span class="line">su - git</span><br><span class="line">gitosis-init&lt; 管理员id_rsa.pub所在路径</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">/home/git下面生成gitosis和repositories</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">确保/home/git/repositories/gitosis-admin.git/hooks/post-update具有执行权限</span></span><br></pre></td></tr></table></figure>

<ul>
<li>管理员的客户端</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git clone git@&lt; server ip &gt;:gitosis-admin.git</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">gitosis-admin项目下有一个gitosis.conf文件和一个keydir目录</span></span><br></pre></td></tr></table></figure>

<p>1、<code>gitosis.conf</code>用来配置 git 项目和用户,<code>keydir</code>存放用户的公钥,公钥必须 pub 结尾</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[gitosis]</span><br><span class="line"></span><br><span class="line">[group gitosis-admin] # gitosis-admin管理所以项目</span><br><span class="line">members = lzoxunc@LAPTOP-DGM7G15T</span><br><span class="line">writable = gitosis-admin  # 对应keydir下有一个 lzoxunc@LAPTOP-DGM7G15T.pub 公钥文件</span><br></pre></td></tr></table></figure>

<ul>
<li>添加新项目</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[gitosis]</span><br><span class="line"></span><br><span class="line">[group gitosis-admin] # gitosis-admin管理所以项目</span><br><span class="line">members = lzoxunc@LAPTOP-DGM7G15T</span><br><span class="line">writable = gitosis-admin  # 对应keydir下有一个 lzoxunc@LAPTOP-DGM7G15T.pub 公钥文件</span><br><span class="line"></span><br><span class="line">[group new-project]  # 手动添加 ，相当于在github创建新项目 产生一个地址 git@192.168.152.130:new-project.git</span><br><span class="line">writable = new-project</span><br><span class="line">members = lzoxunc@LAPTOP-DGM7G15T username2 #多个用户用空格分开,这时keydir下需要存在username2.pub 公钥，</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">多用户，只要username2客户端可以ping 通服务器ip 那么就可以正常使用了</span></span><br></pre></td></tr></table></figure>

<ul>
<li>发布内容</li>
</ul>
<blockquote>
<p>这时 &#x2F;home&#x2F;git&#x2F;repositories 下只有 gitosis-admin.get 一个项目</p>
</blockquote>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"> new-project members 存在的用户客户端任意位置</span></span><br><span class="line">mkdir new-project</span><br><span class="line">cd new-project</span><br><span class="line">git init</span><br><span class="line">git add .</span><br><span class="line">git commit xxx</span><br><span class="line"></span><br><span class="line">git remote add origin git@&lt; server ip &gt;:new-project.git</span><br><span class="line">git push origin master</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">这时 /home/git/repositories 下会多一个new-project.git</span></span><br></pre></td></tr></table></figure>

<h3 id="github"><a href="#github" class="headerlink" title="github"></a>github</h3><ul>
<li>快查看代码<ul>
<li>找到线上项目,按句号，或者将项目添加1s,如:<a target="_blank" rel="noopener" href="https://github1s.com/lzoxun/xxxxx.git%E7%9B%B4%E6%8E%A5%E7%BC%96%E8%BE%91%E5%99%A8%E6%96%B9%E5%BC%8F%E6%89%93%E5%BC%80%E9%A1%B9%E7%9B%AE">https://github1s.com/lzoxun/xxxxx.git直接编辑器方式打开项目</a></li>
</ul>
</li>
<li>查看项目信息<ul>
<li><code>https://api.github.com/repos/用户名称/项目名称</code></li>
</ul>
</li>
</ul>
<h3 id="命令行操作GitHub远程仓库"><a href="#命令行操作GitHub远程仓库" class="headerlink" title="命令行操作GitHub远程仓库"></a>命令行操作GitHub远程仓库</h3><p>生成token<br>    GitHub主页 &gt; settings &gt; Developer settings &gt; Personal access tokens –&gt; Generate new token &gt; 勾选权限 &gt; 生成token令牌<br>    类似 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lzO<br>tolen使用场景文档<br>    <a target="_blank" rel="noopener" href="https://docs.github.com/cn/rest">DOCS</a><br>命令行直接创建仓库<br>    curl -u “$username:$token” <a target="_blank" rel="noopener" href="https://api.github.com/user/repos">https://api.github.com/user/repos</a> -d ‘{“name”:”‘$repo_name’”}’<br>    curl -u “liaozhongxunlzx:ghp_xxx” <a target="_blank" rel="noopener" href="https://api.github.com/user/repos">https://api.github.com/user/repos</a> -d ‘{“name”:”‘lzo-name’”}’<br>    就可以直接<br>    git remote add origin <a target="_blank" rel="noopener" href="https://github.com/liaozhongxunlzx/lzo-name.git">https://github.com/liaozhongxunlzx/lzo-name.git</a></p>
<p>获取GitHub项目列表<br>    curl -H “Authorization: token ghp_xxxxx” <a target="_blank" rel="noopener" href="https://api.github.com/users/liaozhongxun/repos">https://api.github.com/users/liaozhongxun/repos</a><br>    完整的仓库列表<br>    curl -H “Accept: application&#x2F;vnd.github+json” -H “Authorization: token ghp_xxx” <a target="_blank" rel="noopener" href="https://api.github.com/users/liaozhongxun/repos/?page%5C=1%5C&per_page%5C=1000">https://api.github.com/users/liaozhongxun/repos\?page\=1\&amp;per_page\=1000</a></p>
<p>搜索Github其他人的项目<br>    curl -H “Accept: application&#x2F;vnd.github+json” <a target="_blank" rel="noopener" href="https://api.github.com/search/repositories/?q%5C=NAME%5C&sort%5C=stars%5C&page%5C=1%5C&per_page%5C=100%60%60">https://api.github.com/search/repositories\?q\=NAME\&amp;sort\=stars\&amp;page\=1\&amp;per_page\=100``</a></p>
<h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><p>远程 ssh: connect to host github.com port 22: Connection refused</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">$ vim ~/.ssh/config</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Add section below to it</span></span><br><span class="line">Host github.com</span><br><span class="line">  Hostname ssh.github.com</span><br><span class="line">  Port 443</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Host github.com</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">User github的邮箱 如果有邮箱的key</span></span><br><span class="line">Hostname ssh.github.com</span><br><span class="line">PreferredAuthentications publickey</span><br><span class="line">IdentityFile ~/.ssh/id_rsa</span><br><span class="line">Port 443</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">测试</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">$ ssh -T git@github.com</span></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">lzoxun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/07/22/other/other-git/">http://example.com/2023/07/22/other/other-git/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">学习笔记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/07/22/other/other-charles/" title="charles 手机调试"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">charles 手机调试</div></div></a></div><div class="next-post pull-right"><a href="/2023/07/22/other/other-grafana/" title="grafana"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">grafana</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lzoxun</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/liaozhongxun"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaozhongxun" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:869664233@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是我的文档</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE"><span class="toc-number">1.</span> <span class="toc-text">配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE"><span class="toc-number">1.1.</span> <span class="toc-text">用户配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E4%BB%93%E5%BA%93"><span class="toc-number">1.2.</span> <span class="toc-text">获取仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA%E9%97%B4"><span class="toc-number">1.3.</span> <span class="toc-text">工作区间</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E7%8A%B6%E6%80%81"><span class="toc-number">1.4.</span> <span class="toc-text">文件状态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E6%9C%AC%E5%9C%B0%E5%88%B0%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E6%B5%81%E7%A8%8B"><span class="toc-number">1.5.</span> <span class="toc-text">从本地到远程仓库流程</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8C%87%E4%BB%A4"><span class="toc-number">2.</span> <span class="toc-text">指令</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E6%8C%87%E4%BB%A4"><span class="toc-number">2.1.</span> <span class="toc-text">常用指令</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%92%A4%E9%94%80"><span class="toc-number">2.2.</span> <span class="toc-text">撤销</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">2.3.</span> <span class="toc-text">远程仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF"><span class="toc-number">2.4.</span> <span class="toc-text">分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C"><span class="toc-number">2.5.</span> <span class="toc-text">文件操作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BF%BD%E7%95%A5%E6%96%87%E4%BB%B6-gitignore"><span class="toc-number">3.</span> <span class="toc-text">忽略文件 .gitignore</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#GIT-%E5%8D%8F%E8%AE%AE"><span class="toc-number">4.</span> <span class="toc-text">GIT 协议</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#SSH"><span class="toc-number">4.1.</span> <span class="toc-text">SSH</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#linux-%E4%B8%8E-linux-ssh-%E8%AE%BE%E7%BD%AE"><span class="toc-number">4.2.</span> <span class="toc-text">linux 与 linux ssh 设置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#git-%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">5.</span> <span class="toc-text">git 服务器环境搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#github"><span class="toc-number">5.1.</span> <span class="toc-text">github</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%93%8D%E4%BD%9CGitHub%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">5.2.</span> <span class="toc-text">命令行操作GitHub远程仓库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%97%AE%E9%A2%98"><span class="toc-number">5.3.</span> <span class="toc-text">问题</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-11/" title="win 11 set">win 11 set</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-gitbash/" title="git bash">git bash</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-wsl/" title="wsl">wsl</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-main/" title="window">window</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/web/%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98/" title="兼容问题">兼容问题</a><time datetime="2023-07-22T07:14:09.699Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By lzoxun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/haruto.model.json"},"display":{"position":"right","width":100,"height":200,"right":300},"mobile":{"show":true}});</script></body></html>